package com.exm.collectcodenew.juc.threadlocal;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadLocalMemoryLeak {
    static class LocalVariable{
        private Long[] a = new Long[1024* 1024];
    }
    final static ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5,5,1,
            TimeUnit.MINUTES,new LinkedBlockingDeque<>());
    final static ThreadLocal<LocalVariable> localVariable = new ThreadLocal<LocalVariable>();

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 50; i++) {
            poolExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    localVariable.set(new LocalVariable());
                    System.out.println("use local varaible");
                    //localVariable.remove();
                }
            });
            Thread.sleep(1000);
        }
        System.out.println("pool execute over");
    }
}
